package com.baitiaojun.video.handler;

//import com.alibaba.csp.sentinel.slots.block.BlockException;
//import com.alibaba.csp.sentinel.slots.system.SystemRule;
//import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
import com.baitiaojun.api.vo.JsonRes;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @类名 GlobalSystemDefendHandler
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/1/19 14:39
 * @版本 1.0
 */
@Component
public class GlobalSystemDefendHandler {

    public static JsonRes defaultExHandler(Integer pageNo, Integer pageSize, BlockException exception) throws Exception {
        exception.printStackTrace();
        return JsonRes.builder().error(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用");
    }

    @PostConstruct
    public void intiRule() {
        List<SystemRule> rules = new ArrayList<>();
        SystemRule rule = new SystemRule();
        rule.setAvgRt(10000);
        rules.add(rule);
        SystemRuleManager.loadRules(rules);
    }
}
